var fs = require('fs');
var path = require('path');

var filePath1 = path.join(__dirname, '/from.txt');
var filePath2 = path.join(__dirname, '/to.txt');

var readable = fs.createReadStream(filePath1);
var writable = fs.createWriteStream(filePath2);

readable.on("data", function(chunk){
    var chunk = chunk.toString("utf-8").toUpperCase();
    var result = chunk.slice(0,-2);
    writable.write(chunk);
    if(result == ""){
        readable.emit("end");
    }
})

readable.on("end", function(){
    console.log("readable ended");
})
